package com.game77.guessTheWords2.core;

import android.app.Activity;
import android.content.SharedPreferences;

import com.game77.guessTheWords2.R;
import com.game77.guessTheWords2.util.ADHelper;
import com.wiyun.engine.nodes.CharMap;
import com.wiyun.engine.opengl.Texture2D;
import com.wiyun.engine.sound.AudioManager;
import com.wiyun.engine.types.WYRect;

public class GameSystem {
	public static Activity AndroidContext;
	public static SharedPreferences SharedSettings;
	/**
	 * 屏幕宽度
	 */
	public static int Screen_Width = 480;

	/**
	 * 屏幕高度
	 */
	public static int Screen_Height = 800;

	/**
	 * 游戏行数
	 */
	public static int GameRows = 10;

	/**
	 * 游戏列数
	 */
	public static int GameColumns = 10;

	/**
	 * 游戏两边留空
	 */
	public static final int Margin_Side = 26;

	public static int GameMatrixStartY = 756;

	/**
	 * 字符框大小
	 */
	public static final float CharSize = 36;

	/**
	 * 字符框中的字符大小
	 */
	public static final int CharBlockFontSize = 25;

	// 按钮高度宽度
	public static final float KeyHeight = 51;
	public static final float KeyWidth = 60;

	// Tip
	public static final int TipFontSize = 24;

	// stage 相关
	public static final int stageCount = 50;

	// classCount
	public static final int ClassCount = 8;

	// 当前开放的关卡数目
	public static final int CurrentClassOpenCount = 5;

	public static boolean isLowPxPhone = false;

	public static void loadAllResource() {
		loadTexture();
		loadCharMap();
		loadSound();
		initSetting();
		ADHelper.initAD();
	}

	private static void loadSound() {
		AudioManager.preloadBackgroundMusic(R.raw.background);
		AudioManager.preloadEffect(R.raw.clickbutton);
		AudioManager.preloadEffect(R.raw.keyboard);
		AudioManager.preloadEffect(R.raw.right);
		AudioManager.preloadEffect(R.raw.selectchar);
		AudioManager.preloadEffect(R.raw.selectnull);
		AudioManager.preloadEffect(R.raw.buy);
	}

	public static CharMap charMap;

	private static void loadCharMap() {
		charMap = CharMap.make();
		for (int i = 0; i < 10; i++) {
			charMap.mapChar(WYRect.make(i * 30, 0, 30, 40),
					(i + "").toCharArray()[0]);
		}
	}

	public static Texture2D tex_char_background;
	public static Texture2D tex_game_background;
	public static Texture2D tex_main_background;
	public static Texture2D tex_stage_block;
	public static Texture2D tex_stage_block_locked;
	public static Texture2D tex_numbers_48;
	public static Texture2D tex_star_full;
	public static Texture2D tex_star_empty;
	public static Texture2D tex_shop_background;
	public static Texture2D tex_class_back;
	public static Texture2D tex_stage_back;
	public static Texture2D tex_matrix_back;
	public static Texture2D tex_tip_back;
	public static Texture2D tex_coin_inclass;
	public static Texture2D tex_bottombar;

	private static void loadTexture() {

		if (isLowPxPhone) {
			tex_char_background = Texture2D
					.makePNG(R.drawable.char_background_lowpx);
		} else {
			tex_char_background = Texture2D.makePNG(R.drawable.char_background);
		}
		tex_game_background = Texture2D.makePNG(R.drawable.gamebackground);
		tex_main_background = Texture2D.makePNG(R.drawable.main_background);
		tex_stage_block = Texture2D.makePNG(R.drawable.stage_block);
		tex_stage_block_locked = Texture2D
				.makePNG(R.drawable.stage_block_locked);
		tex_numbers_48 = Texture2D.makePNG(R.drawable.numbers_48);
		tex_star_full = Texture2D.makePNG(R.drawable.star_full);
		tex_star_empty = Texture2D.makePNG(R.drawable.star_empty);
		tex_shop_background = Texture2D.makePNG(R.drawable.shopbackground);
		tex_class_back = Texture2D.makePNG(R.drawable.class_background);
		tex_stage_back = Texture2D.makePNG(R.drawable.stage_background);
		tex_matrix_back = Texture2D.makePNG(R.drawable.matrix_background);
		tex_tip_back = Texture2D.makePNG(R.drawable.tip_background);
		tex_coin_inclass = Texture2D.makePNG(R.drawable.coin_inclass);
		tex_bottombar = Texture2D.makePNG(R.drawable.bottombar);

		tex_bottombar.loadTexture();
		tex_coin_inclass.loadTexture();
		tex_tip_back.loadTexture();
		tex_matrix_back.loadTexture();
		tex_stage_back.loadTexture();
		tex_class_back.loadTexture();
		tex_shop_background.loadTexture();
		tex_star_full.loadTexture();
		tex_star_empty.loadTexture();
		tex_stage_block.loadTexture();
		tex_stage_block_locked.loadTexture();
		tex_main_background.loadTexture();
		tex_char_background.loadTexture();
		tex_game_background.loadTexture();
	}

	private static void initSetting() {
		SharedSettings = AndroidContext.getPreferences(Activity.MODE_PRIVATE);
		StageManager.instance.initStageData();
	}
}
